#include <bits/stdc++.h>
using namespace std;

int my_stack[10000000], st = 0;

void stack_method(int n)
{
    switch (n)
    {
        case 0: // push
            cin >> my_stack[st];
            st++;
            break;
        case 1: // pop
            if (st > 0) {
                st--;
            } else {
                cout << "Anguei!" << endl;
            }
            break;
        case 2: // query
            if (st > 0) {
                cout << my_stack[st - 1] << endl;
            } else {
                cout << "Empty" << endl;
            }
            break;
        case 3: // size
            cout << st << endl;
            break;
    }
}

int main()
{
    int T, n, i;
    string s, ss[] = {"push", "pop", "query", "size"};
    cin >> T;
    while (T--)
    {
        cin >> n;
        while (n--)
        {
            cin >> s;

            i = 4;
            while (i != 0)
            {
                if (s == ss[i - 1])
                {
                    break;
                }
                i--;
            }

            if (i == 0)
            {
                break;
            }

            stack_method(i - 1);
        }
    }
    system("pause");
}